package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCLocationData.RouteAddition;

public class RouteAdditionDto {
    private long areaId;
    private long lineId;
    private int routeTime;
    private boolean routeResult;

    public long getAreaId() {
        return areaId;
    }
    public void setAreaId(long areaId) {
        this.areaId = areaId;
    }
    public long getLineId() {
        return lineId;
    }
    public void setLineId(long lineId) {
        this.lineId = lineId;
    }
    public int getRouteTime() {
        return routeTime;
    }
    public void setRouteTime(int routeTime) {
        this.routeTime = routeTime;
    }
    public boolean isRouteResult() {
        return routeResult;
    }
    public void setRouteResult(boolean routeResult) {
        this.routeResult = routeResult;
    }

    public static RouteAdditionDto parseProto(RouteAddition routeAddition){
        RouteAdditionDto routeAdditionDto = new RouteAdditionDto();
        routeAdditionDto.setAreaId(routeAddition.getAreaId());
        routeAdditionDto.setLineId(routeAddition.getLineId());
        routeAdditionDto.setRouteResult(routeAddition.getRouteResult());
        routeAdditionDto.setRouteTime(routeAddition.getRouteTime());
        return routeAdditionDto;
    }

    /**
     * 解析成String拼接字符串
     * @param routeAddition
     * @return
     */
    public static String parseString(RouteAddition routeAddition){
        return EntityConvert.convert(
                routeAddition.getAreaId(),
                routeAddition.getLineId(),
                routeAddition.getRouteResult(),
                routeAddition.getRouteTime());
    }

    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static RouteAddition parsePB(String str){
        RouteAddition.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=4){
                builder = RouteAddition.newBuilder();
                builder.setAreaId(Long.valueOf(revert[0]));
                builder.setLineId(Long.valueOf(revert[1]));
                builder.setRouteResult(Boolean.valueOf(revert[2]));
                builder.setRouteTime(Integer.valueOf(revert[3]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }

}
